
package app_core

import (
	"context"
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/app_core"
    app_coreReq "github.com/flipped-aurora/gin-vue-admin/server/model/app_core/request"
)

type HbjgCampusLocationService struct {}
// CreateHbjgCampusLocation 创建建筑表记录
// Author [yourname](https://github.com/yourname)
func (hbjgCampusLocationService *HbjgCampusLocationService) CreateHbjgCampusLocation(ctx context.Context, hbjgCampusLocation *app_core.HbjgCampusLocation) (err error) {
	err = global.GVA_DB.Create(hbjgCampusLocation).Error
	return err
}

// DeleteHbjgCampusLocation 删除建筑表记录
// Author [yourname](https://github.com/yourname)
func (hbjgCampusLocationService *HbjgCampusLocationService)DeleteHbjgCampusLocation(ctx context.Context, ID string) (err error) {
	err = global.GVA_DB.Delete(&app_core.HbjgCampusLocation{},"id = ?",ID).Error
	return err
}

// DeleteHbjgCampusLocationByIds 批量删除建筑表记录
// Author [yourname](https://github.com/yourname)
func (hbjgCampusLocationService *HbjgCampusLocationService)DeleteHbjgCampusLocationByIds(ctx context.Context, IDs []string) (err error) {
	err = global.GVA_DB.Delete(&[]app_core.HbjgCampusLocation{},"id in ?",IDs).Error
	return err
}

// UpdateHbjgCampusLocation 更新建筑表记录
// Author [yourname](https://github.com/yourname)
func (hbjgCampusLocationService *HbjgCampusLocationService)UpdateHbjgCampusLocation(ctx context.Context, hbjgCampusLocation app_core.HbjgCampusLocation) (err error) {
	err = global.GVA_DB.Model(&app_core.HbjgCampusLocation{}).Where("id = ?",hbjgCampusLocation.ID).Updates(&hbjgCampusLocation).Error
	return err
}

// GetHbjgCampusLocation 根据ID获取建筑表记录
// Author [yourname](https://github.com/yourname)
func (hbjgCampusLocationService *HbjgCampusLocationService)GetHbjgCampusLocation(ctx context.Context, ID string) (hbjgCampusLocation app_core.HbjgCampusLocation, err error) {
	err = global.GVA_DB.Where("id = ?", ID).First(&hbjgCampusLocation).Error
	return
}
// GetHbjgCampusLocationInfoList 分页获取建筑表记录
// Author [yourname](https://github.com/yourname)
func (hbjgCampusLocationService *HbjgCampusLocationService)GetHbjgCampusLocationInfoList(ctx context.Context, info app_coreReq.HbjgCampusLocationSearch) (list []app_core.HbjgCampusLocation, total int64, err error) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&app_core.HbjgCampusLocation{})
    var hbjgCampusLocations []app_core.HbjgCampusLocation
    // 如果有条件搜索 下方会自动创建搜索语句
    if len(info.CreatedAtRange) == 2 {
     db = db.Where("created_at BETWEEN ? AND ?", info.CreatedAtRange[0], info.CreatedAtRange[1])
    }
    
	err = db.Count(&total).Error
	if err!=nil {
    	return
    }

	if limit != 0 {
       db = db.Limit(limit).Offset(offset)
    }

	err = db.Find(&hbjgCampusLocations).Error
	return  hbjgCampusLocations, total, err
}
func (hbjgCampusLocationService *HbjgCampusLocationService)GetHbjgCampusLocationPublic(ctx context.Context) {
    // 此方法为获取数据源定义的数据
    // 请自行实现
}
